package com.hax2max.view;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;

import com.hax2max.model.Profile;

public class MapItemMarker extends MapItemPressable {
	
	private static final int CIRCLERADIUS = 4;
	protected Profile profile = null;
	protected double distance = 999999;
	private Paint text = null;
	private Paint circle = null;
	private Paint background = null;
	private RectF rect = null;

	public MapItemMarker(Canvas canvas, Point point, BitmapDrawable pic,BitmapDrawable picPressed, Profile profile) {
		super(canvas, point, pic, picPressed);
		initGraphics(profile);		
	}	
	
	private void initGraphics(Profile profile)
	{
		this.profile = profile;
		
		this.text = new Paint();
		this.text.setAntiAlias(true);
		this.text.setColor(Color.BLUE);
		this.text.setTextSize(12);
		this.text.setTypeface(Typeface.MONOSPACE);
		
		this.circle = new Paint();
		this.circle.setColor(Color.BLUE);
		this.circle.setAntiAlias(true);
		
		this.background = new Paint();
		this.background.setColor(Color.WHITE);
		this.rect = new RectF();
	}

	@Override
	public void draw() {
				
 
		// background
		if(!pressed){
			rect.set(point.x-55, point.y+24, point.x + 5, point.y+40 );
			
			pic.setBounds((point.x-pic.getIntrinsicWidth()), point.y, point.x, (point.y+pic.getIntrinsicHeight()));
			//left top right bottom
			
			pic.draw(canvas);
			canvas.drawRoundRect(rect, 2, 2, background);
			
			canvas.drawCircle(point.x, point.y, CIRCLERADIUS, circle);
			
			canvas.drawText(profile.username, (point.x-50) , point.y+37, text);
		}
		else{
			rect.set(point.x-55, point.y+24, point.x + 5, point.y+40 );
			
			picPressed.setBounds((point.x-pic.getIntrinsicWidth()), point.y, point.x, (point.y+pic.getIntrinsicHeight()));
			//left top right bottom
			
			picPressed.draw(canvas);
			canvas.drawRoundRect(rect, 2, 2, background);
			
			canvas.drawCircle(point.x, point.y, CIRCLERADIUS, circle);
			
			canvas.drawText(profile.username, (point.x-50) , point.y+37, text);
		}

	}

}
